package com.hcinfos.gsoo.adapter;

import java.util.List;

import com.hcinfos.gsoo.R;
import com.hcinfos.gsoo.ui.ShopDetailActivity;

import android.content.Context;
import android.content.Intent;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;

public class MainFocusAdapter extends PagerAdapter {

	private LayoutInflater inflater;
	private Context context;
	private List<String> list;
	public static int test = 0;

	public MainFocusAdapter(List<String> list, Context context) {
		this.context = context;
		this.list = list;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0 == arg1;
	}

	@Override
	public int getItemPosition(Object object) {
		return super.getItemPosition(object);
	}

	@Override
	public Object instantiateItem(ViewGroup container, final int position) {
		View imageLayout = inflater.inflate(R.layout.focus_view, container,
				false);
		ImageView imageView = (ImageView) imageLayout
				.findViewById(R.id.imageView);
		if (test == 1) {
			if (position == 0) {
				imageView.setBackgroundResource(R.drawable.test_diancai);
			} else {
				imageView.setBackgroundResource(R.drawable.slide_test_2);
			}
		} else {
			imageView.setBackgroundResource(R.drawable.test_big_img);
		}
		((ViewPager) container).addView(imageLayout);
		imageLayout.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				String id = "42362da04c4c4440974bec12432a0460";
				if (position == 0) {
					id = "66d87ee1c0294a8d92a0a1bb7d5450fa";
				}
				Intent intent = new Intent(context, ShopDetailActivity.class);
				intent.putExtra("suppId", id);
				context.startActivity(intent);
			}
		});

		return imageLayout;
	}

	@Override
	public void restoreState(Parcelable arg0, ClassLoader arg1) {

	}

	@Override
	public Parcelable saveState() {
		return null;
	}

	@Override
	public void startUpdate(View arg0) {

	}

	@Override
	public void finishUpdate(View arg0) {

	}

	@Override
	public void destroyItem(View container, int position, Object object) {
		((ViewPager) container).removeView((View) object);
	}
}